/*
 * TypeFilter.java
 * 
 * @version 1.0, April 27, 2011
 * CS 2340 Team 10: Cyberdyne Systems
 */
package edu.gatech.oad.cyberdoc.domain.filter;

import edu.gatech.oad.cyberdoc.domain.User;

/**
 * Filters users based on the object's class.
 * 
 * @author John Girata
 * @version 1.0, April 27, 2011
 */
public class TypeFilter implements Filter {

	/**
	 * The type to check for.
	 */
	private final Class<?> type;

	/**
	 * Creates a new TypeFilter allowing only the specified type.
	 * 
	 * @param type
	 *            The type to allow
	 */
	public TypeFilter(Class<?> type) {
		this.type = type;
	}

	/**
	 * Determines if the specified user passes.
	 * 
	 * @param user
	 *            The user to check
	 * @return true if the user passes, false otherwise
	 */
	@Override
	public boolean accept(User user) {
		return type.isInstance(user);
	}

	/**
	 * Returns a useful string representation of this class.
	 * 
	 * @return A string representing this class
	 */
	@Override
	public String toString() {
		return "TypeFilter [type=" + type + "]";
	}
}
